export default {
  state: {
    userInfo: uni.getStorageSync('userInfo') || {},
    token: uni.getStorageSync('token') || '',
    refreshToken: uni.getStorageSync('refreshToken') || '',
    sid: uni.getStorageSync('sid') || ''
  },
  mutations: {
    setUserInfo (state, val) {
      if (val === '') return
      state.userInfo = val
      uni.setStorageSync('userInfo', val)
    },
    setToken (state, val) {
      state.token = val
      uni.setStorageSync('token', val)
    },
    setRefreshToken (state, val) {
      state.refreshToken = val
      uni.setStorageSync('refreshToken', val)
    },
    setSid (state, val) {
      state.sid = val
      uni.setStorageSync('sid', val)
    }
  },
  getters: {
    isLogin (state) {
      return typeof state.userInfo._id !== 'undefined'
    }
  },
  actions: {
    logout ({ commit }) {
      commit('setToken', '')
      commit('setUserInfo', {})
      commit('setRefreshToken', '')
      uni.clearStorage()
    }
  }
}